import 'package:any_reader/public.dart';

//"book_id": bookId,
//"book_Name": bookName,
//"author": author,
//"rule": rule,
//"chapter_id": chapterId,
//"cover": cover,
//"total": total,
//"now": now,
//"position": position,

class Book {
  String bookId;
  String title;
  String author;
  String description;
  String imgUrl;
  String baseUrl;
  String originUrl;
  String url;
  String updateTime;
  String bookType;
  String bookStatus;
  String reptileType;
  String reptileType1;
  String total;
  String now;
  String position;
  Book({
    Key key,
    @required this.bookId,
    @required this.title,
    @required this.author,
    @required this.description,
    @required this.imgUrl,
    this.baseUrl,
    this.originUrl,
    this.url,
    this.updateTime,
    this.bookType = "",
    this.bookStatus = "",
    this.reptileType = "",
    this.reptileType1 = "",
    this.total = "",
    this.now = "",
    this.position = "",
  });
  factory Book.fromJson({
    String bookId,
    String title,
    String author,
    String description,
    String imgUrl,
    String baseUrl = "",
    String originUrl = "",
    String url = "",
    String updateTime = "",
    String bookType = "",
    String bookStatus = "",
    String reptileType = "",
    String reptileType1 = "",
    String total = "",
    String now = "",
    String position = "",
  }) {
    return Book(
      bookId: bookId,
      title: title,
      author: author,
      description: description,
      imgUrl: imgUrl,
      baseUrl: baseUrl,
      originUrl: originUrl,
      url: url,
      updateTime: updateTime,
      bookType: bookType,
      bookStatus: bookStatus,
      reptileType: reptileType,
      reptileType1: reptileType1,
      total: total,
      now: now,
      position: position,
    );
  }
  static Book bookFromJson(dynamic json) {
    Book _book = new Book(
      bookId: json['bookId'].toString(),
      title: json['name'].toString(),
      author: json['author'].toString(),
      description: json['description'].toString().replaceAll("<br>", ""),
      imgUrl: json['imgUrl'].toString(),
      baseUrl: json['baseUrl'].toString(),
      originUrl: json['originUrl'].toString(),
      updateTime: json['updateTime'].toString(),
      bookType: json['bookType'].toString(),
      bookStatus: json['bookStatus'].toString(),
      reptileType: json['reptileType'].toString(),
      reptileType1: json['reptileType'].toString(),
    );
    return _book;
  }

  static List<Book> listFromJson(Map<String, dynamic> json) {
    List<Book> _ret = [];
    List<dynamic> urlList = json['urlList'];
    if (urlList.length > 0) {
      urlList.forEach((value) {
        String reptileType = value['reptileType'];
        List<dynamic> _listJson = value['list'];
        _listJson.forEach((element) {
          _ret.add(Book.fromJson(
            title: element['title'],
            author: element['author'],
            description:
                element['description'].toString().replaceAll("<br>", ""),
            imgUrl: element['imgUrl'],
            baseUrl: element['baseUrl'],
            originUrl: element['originUrl'],
            url: element['url'],
            updateTime: element['updateTime'],
            bookType: element['bookType'],
            bookStatus: element['bookStatus'],
            reptileType: element['reptileType'].toString(),
            reptileType1: reptileType,
          ));
        });
      });
    }
    return _ret;
  }

  static List<Book> listFromJson2(Map<String, dynamic> json) {
    List<Book> _ret = [];
    List<dynamic> urlList = json['book'];
    if (urlList.length > 0) {
      urlList.forEach((value) {
        _ret.add(Book.fromJson(
          title: value['name'],
          author: value['author'],
          description: value['description'].toString().replaceAll("<br>", ""),
          imgUrl: value['imgUrl'],
          baseUrl: value['baseUrl'],
          originUrl: value['originUrl'],
          url: value['url'],
          updateTime: value['updateTime'],
          bookType: value['bookType'],
          bookStatus: value['bookStatus'].toString(),
          reptileType: value['reptileType'].toString(),
          reptileType1: "0",
        ));
      });
    }
    return _ret;
  }
}
